package com.hjhz.action;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.SessionAware;

import com.hjhz.pojo.User;
import com.hjhz.service.UserService;
import com.opensymphony.xwork2.ActionSupport;


public class AppAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = 1L;
	private User user;
	private String code;
	private UserService userService;
	private Map<String,Object> session;

	@Action(value="index",params={"code","${param.code}"})
	public String execute(){
		return "success";
	}
	
	

	@Action(value="login",results={
			@Result(name="error",type="redirectAction",params={"actionName","index","code","${param.code}"})
			
	})
	public String login(){
		if(user!=null&&!"".equals(user.getUSER_NAME())&&!"".equals(user.getUSER_PASSWORD())){
			User u = userService.find("USER_NAME",user.getUSER_NAME());
			if(u!=null&&u.getUSER_PASSWORD().equals(user.getUSER_PASSWORD())){
				session.put("cur_user",u);
				return "success";
			}
			code="10000";
			return "error";
		}
		code="10000";
		return "error";
	}
	
	
	//get set
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}
	
}
